﻿using Apewer;
using Apewer.Network;
using System;
using System.Net;

namespace Apewer.Web
{

    /// <summary></summary>
    [Serializable]
    public sealed class ApiRequest
    {

        private Json _data = null;
        internal string[] _segmentals = null;

        /// <summary>自定义标签。</summary>
        public object Tag { get; set; }

        #region http

        /// <summary>客户端 IP 地址。</summary>
        public string IP { get; set; }

        /// <summary></summary>
        public Uri Url { get; set; }

        /// <summary></summary>
        public string Referrer { get; set; }

        /// <summary>HTTP 头中的 User Agent 字符串。</summary>
        public string UserAgent { get; set; }

        /// <summary>HTTP 方法。</summary>
        public HttpMethod Method { get; set; }

        /// <summary>已解码的 URL 参数。</summary>
        public StringPairs Parameters { get; set; } = new StringPairs();

        /// <summary>HTTP 头。</summary>
        public HttpHeaders Headers { get; set; } = new HttpHeaders();

        /// <summary>Cookies。</summary>
        public CookieCollection Cookies { get; set; } = new CookieCollection();

        #endregion

        #region api

        /// <summary></summary>
        public string Application { get; set; }

        /// <summary></summary>
        public string Function { get; set; }

        /// <summary></summary>
        public string Random { get; set; }

        /// <summary></summary>
        public string Ticket { get; set; }

        /// <summary></summary>
        public string Session { get; set; }

        /// <summary></summary>
        public string Page { get; set; }

        #endregion

        #region post

        /// <summary></summary>
        public byte[] PostData { get; set; }

        /// <summary></summary>
        public string PostText { get; set; }

        /// <summary></summary>
        public Json PostJson { get; set; }

        /// <summary>已解码的 POST 参数，仅当内容类型为 application/x-www-form-urlencoded 时有效。</summary>
        public StringPairs Form { get; set; }

        /// <summary></summary>
        public Json Data
        {
            get
            {
                if (_data == null) _data = Json.NewObject();
                return _data;
            }
            set { _data = value; }
        }

        #endregion

    }

}
